package com.yoomiito.app.widget.dialog

import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.yoomiito.app.BuildConfig
import com.yoomiito.app.R
import com.yoomiito.app.utils.L
import kotlinx.android.synthetic.main.dialog_push_tip.*
class PushTipDialog :BaseDialog{

    constructor(context: Context) : super(context, R.style.dialog_2) {}

    constructor(context: Context, themeResId: Int) : super(context, R.style.dialog_2) {
    }

    protected constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener?) : super(context, cancelable, cancelListener) {}

    override fun setView(): View {
        val view = LayoutInflater.from(mContext).inflate(R.layout.dialog_push_tip, null, false)
        view.findViewById<ImageView>(R.id.cancel).setOnClickListener { dismiss() }
        view.findViewById<TextView>(R.id.go_push_permission).setOnClickListener {
            val intent = Intent()
            try {
                intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
//                if (Build.VERSION.SDK_INT in Build.VERSION_CODES.LOLLIPOP..Build.VERSION_CODES.N_MR1 ){
//                    intent.putExtra("app_package", mContext.packageName)
//                    intent.putExtra("app_uid", mContext.applicationInfo.uid)
//                }else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
//                    intent.putExtra(Settings.EXTRA_APP_PACKAGE, mContext.packageName)
//                    intent.putExtra(Settings.EXTRA_CHANNEL_ID, mContext.applicationInfo.uid)
//                }
                mContext.startActivity(intent)
            } catch (e: Exception) {
                e.printStackTrace()
                //其他低版本或者异常情况，走该节点。进入APP设置界面
                intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
                intent.putExtra("package", mContext.packageName)
                mContext.startActivity(intent)
            }
        }
        setCanceledOnTouchOutside(false)
        setmGravity(Gravity.CENTER)
        setWidthPercent(1.0)
        setmHeightPercent(1.0)
        return view
    }

    override fun onBackPressed() {
    }

}